home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / t3_1 / mac.lha / mac / macassist.c < prev    next >
C/C++ Source or Header  |  1987-11-25  |  3KB  |  121 lines

  1. #include <stdio.h>
  2. #include <signal.h>
  3.  
  4. #define IF ((
  5. #define THEN )?(
  6. #define ELSE ):(
  7. #define FI ))
  8.  
  9. #define MIN_HEAP_SIZE 524288  /* .5 Mb */
  10. #define MAX_HEAP_SIZE 8192000 /* 8 Mb  */
  11. #define DEFAULT_HEAP_SIZE 4096000 /* 4 Mb  */
  12. #define STDIO_SPACE   49152   /* be sure to save 48k of data space for stdio */
  13. #define STATIC_SPACE  131072  /* .125Mb for fun, usr "-l" to add to this */
  14. #define SAVED_SPACE   (STDIO_SPACE+STATIC_SPACE)
  15.  
  16.  
  17. main( argc, argv )
  18. char **argv;
  19. int argc;
  20. {
  21.     long heap_wanted = -1;
  22.     long leave_wanted = -1;
  23.     long debug = 0;
  24.  
  25.     long
  26.     max_heap_size,
  27.     heap_size;
  28.               
  29.     long
  30.     total,
  31.     aligned_total,
  32.     aligned_heap_size;
  33.  
  34.     char **av;
  35.  
  36.     av = argv;
  37.     av[argc] = 0; /* easy end test */
  38.  
  39.     while (*av)  {
  40.     if ( ( !strcmp( *av, "-h" ) ) || ( !strcmp( *av, "-heap" ) ) )
  41.         heap_wanted = IF (!*++av) THEN -2 ELSE atoi( *av ) FI;
  42.     else if ( ( !strcmp( *av, "-l" ) ) || ( !strcmp( *av, "-leave" ) ) )
  43.         leave_wanted = IF (!*++av) THEN -2 ELSE atoi( *av ) FI;
  44.     else if (!strcmp( *av, "-d" ) )
  45.         debug = -1;
  46.     av++;
  47.     }
  48.  
  49.     /* Compute max allowed heap size.  MIN in case datasize is big. */
  50.     /*  Quad align. */
  51.  
  52.     max_heap_size = MAX_HEAP_SIZE;
  53.                    
  54.     /* decide what to allocate - give user his request if it's within reason */
  55.  
  56.     if ((heap_wanted == -2) || (heap_wanted > MAX_HEAP_SIZE))
  57.     heap_size = MAX_HEAP_SIZE;
  58.     else                      
  59.     if (heap_wanted == -1)
  60.     heap_size = DEFAULT_HEAP_SIZE;
  61.     else
  62.     if (heap_wanted > MIN_HEAP_SIZE)
  63.     heap_size = heap_wanted;
  64.     else
  65.     heap_size = MIN_HEAP_SIZE;
  66.  
  67.     total = sbrk( heap_size * 2 );
  68.     if (total == -1)  {
  69.     printf( "T could not allocate two heaps of %d bytes.\n", heap_size);
  70.     printf( "Please retry with smaller heaps by using the -h switch.\n");
  71.     exit(1);
  72.     }
  73.         
  74.     /* make heaps smaller (if necessary) for quadword alignment */
  75.  
  76.     aligned_total = (total + 15) & 0xFFFFFFF0;
  77.     aligned_heap_size = ( ((heap_size * 2) - (aligned_total - total))
  78.               & 0xFFFFFFC0 );
  79.  
  80.     heap_size = aligned_heap_size / 2;
  81.  
  82.     /* print message if any command line flag is given */
  83.  
  84.     if ( (heap_wanted != -1) || (leave_wanted != -1) )
  85.     printf( "%d bytes per heap, %d bytes reserved\n",
  86.         heap_size, leave_wanted + STATIC_SPACE );
  87.  
  88.     set42sig();
  89.     start_t( aligned_total, (aligned_total + heap_size), heap_size, 
  90.              argc, argv, debug);
  91.  
  92. }
  93.  
  94. gc_interrupt()
  95. {
  96.   printf("Interrupted during GC; 'q' to exit, anything else to continue GC.\n");
  97.   if (getchar() == 'q')
  98.      exit(0);
  99. }
  100.  
  101. csh()
  102. { }
  103.  
  104. extern int errno;
  105. extern char *sys_errlist[];
  106. extern int sys_nerr;
  107.  
  108. get_unix_error_msg(t, size) 
  109. char *t;
  110. int size; 
  111. {
  112.   char *s;    
  113.   int i;
  114.  
  115.   i = 0;
  116.   s = (char *) sys_errlist[ errno ];
  117.   while (i<size && ((*t++ = *s++) != '\0')) i++; 
  118. }
  119.  
  120.  
  121.